﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Skyhook.Core;
using Microsoft.Xna.Framework;

namespace Skyhook.AI.Animators
{
    public class LoopIntegerAnimator : Animator
    {
        public const int ValueInfty = 0x0FFFFFFF;

        LoopInteger LoopInteger = null;
        
        float pRotateDelay = 0.0f;
        float ElapsedDelay = 0.0f;
        int pDestinationValue = 0;

        public LoopIntegerAnimator(LoopInteger loopinteger)
            :base()
        {
            LoopInteger = loopinteger;
        }

        public float RotateDelay
        {
            get
            {
                return pRotateDelay;
            }
            set
            {
                CheckIfIsFinished();

                pRotateDelay = value;
            }
        }

        public int DestinationValue
        {
            get
            {
                return pDestinationValue;
            }
            set
            {
                CheckIfIsFinished();

                pDestinationValue = value;
            }
        }

        protected override void DoActualUpdate(float elapsedticks)
        {
            ElapsedDelay += elapsedticks;

            if (ElapsedDelay >= pRotateDelay)
            {
                int anglesrotated = (int)(ElapsedDelay / pRotateDelay);
                LoopInteger.Change(anglesrotated);
                ElapsedDelay = ElapsedDelay - anglesrotated * pRotateDelay;
            }
            
        }
    }
}
